<?php

include 'DBconn.php';

class CompanyMaster {

    public function getCompany() {
        $res = mysql_query("select serialnumber,company_name from company_header where activestatus=1") or die(mysql_error());
        $ret = array();
        while ($row = mysql_fetch_object($res)) {
            $ret[] = $row;
        }
        return $ret;
    }

    public function getAllCompanies() {
        $result = mysql_query("Select ch.serialnumber,ch.company_name,ch.country_serialnumber_fk,ch.state_serialnumber_fk,ch.company_address1,ch.company_address2,ch.company_city,ch.company_zip,ch.company_phone,ch.company_fax,ch.company_email,ch.company_url,ch.company_regno1,ch.gst_code,ch.cre_userid,ch.cre_datetime,ch.activestatus,con.country_name from company_header as ch LEFT JOIN country_header as con ON con.activestatus=1 and con.serialnumber=ch.country_serialnumber_fk 
		where ch.activestatus=1") or die(mysql_error());
        $res_arr = array();
        while ($row = mysql_fetch_object($result)) {
            $tmp = new VoCompanyMaster();
            $tmp->serialnumber = (int) $row->serialnumber;
            $tmp->company_name = $row->company_name;
			$tmp->country_name = $row->country_name;
            $tmp->country_serialnumber_fk = (int) $row->country_serialnumber_fk;
            $tmp->state_serialnumber_fk = (int) $row->state_serialnumber_fk;
            $tmp->company_address1 = $row->company_address1;
            $tmp->company_address2 = $row->company_address2;
            $tmp->company_zip = $row->company_zip;
            $tmp->company_city = $row->company_city;
            $tmp->company_phone = $row->company_phone;
            $tmp->company_fax = $row->company_fax;
            $tmp->company_email = $row->company_email;
            $tmp->company_url = $row->company_url;
            $tmp->company_regno1 = $row->company_regno1;
            $tmp->gst_code = $row->gst_code;
            $tmp->cre_userid = (int) $row->cre_userid;
            $tmp->cre_datetime = $row->cre_datetime;
            $tmp->activestatus = $row->activestatus;
            $res_arr[] = $tmp;
        }
        mysql_free_result($result);
        return $res_arr;
    }

    public function addNewCompany($VObject) {
        $query = "insert into company_header(company_name,country_serialnumber_fk,state_serialnumber_fk,company_address1,company_address2,company_city,company_zip,company_phone,company_fax,company_email,company_url,company_regno1,gst_code,cre_userid,cre_datetime,activestatus) values('$VObject->company_name','$VObject->country_serialnumber_fk','$VObject->state_serialnumber_fk','$VObject->company_address1','$VObject->company_address2','$VObject->company_city','$VObject->company_zip','$VObject->company_phone','$VObject->company_fax','$VObject->company_email','$VObject->company_url','$VObject->company_regno1','$VObject->gst_code','$VObject->cre_userid','$VObject->cre_datetime',1)";
        $s = mysql_query($query) or die(mysql_error());
        return $this->getAllCompanies();
    }

    public function deleteCompany($serialnumber) {
        $query = "update company_header set activestatus=0 where serialnumber=" . $serialnumber;
        $s = mysql_query($query) or die(mysql_error());
        return $serialnumber;
    }

    public function editCompany($VObject) {
        $query = "update company_header set company_name='$VObject->company_name',country_serialnumber_fk='$VObject->country_serialnumber_fk',state_serialnumber_fk='$VObject->state_serialnumber_fk',company_address1='$VObject->company_address1',company_address2='$VObject->company_address2',company_city='$VObject->company_city',company_zip='$VObject->company_zip',company_phone='$VObject->company_phone',company_fax='$VObject->company_fax',company_email='$VObject->company_email',company_url='$VObject->company_url',company_regno1='$VObject->company_regno1',gst_code='$VObject->gst_code' where serialnumber='$VObject->serialnumber'";
        $s = mysql_query($query) or die(mysql_error());
        return $this->getAllCompanies();
    }

}

class VoCompanyMaster {

    var $serialnumber;
    var $company_name;
	var $country_name;
    var $country_serialnumber_fk;
    var $state_serialnumber_fk;
    var $company_address1;
    var $company_address2;
    var $company_zip;
    var $company_city;
    var $company_phone;
    var $company_fax;
    var $company_email;
    var $company_url;
    var $company_regno1;
    var $gst_code;
    var $cre_userid;
    var $cre_datetime;
    var $activestatus;

}

?>